<%@ include file="/common/include.jsp"%>
<%@ page contentType="text/html; charset=utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<jsp:include page="../../../common/head.jsp">
			<jsp:param name="_useCalendar" value="true"/>
			<jsp:param name="_useUpload" value="true"/>
		</jsp:include>
		<script language="javascript">
	function saveinfofs()
	{   document.form1.state.value="已发送";
		if(userIds=="")
		{
			alert("请选择接收人");
			return false;
		}
		var objarr = new Array(
			["sysMessage.messageTitle","系统标题","notEmpty",""],
			["sysMessage.messageTitle","系统标题","max","String:100"],
			["sysMessage.messageContent","消息内容","notEmpty",""]
		);	
		if(xj.CheckAll(objarr))
		{
			if(confirm("确认发送？"))
			{
				document.form1.submit();
			}
		}
	}
	function saveinfobc()
	{   document.form1.state.value="未发送";
		var objarr = new Array(
			["sysMessage.messageTitle","系统标题","notEmpty",""],
			["sysMessage.messageTitle","系统标题","max","String:100"],
			["sysMessage.messageContent","消息内容","notEmpty",""]
		);	
		if(xj.CheckAll(objarr))
		{
			if(confirm("确认存入草稿箱？"))
			{
				document.form1.submit();
			}
		}
	}
	var userIds = "${userIds}";
	function addUser(that)
	{
		var users=ModalWindow("jump.do?path=${ctx}/jsp/common/user/index.jsp&userIds="+userIds,1000,600);
		if(users!=null)
		{
			$("#receiver").show();
			var arr = new Array();
			arr =  users.split(";");
			for(var i=0;i<arr.length;i++)
			{
				var ar = arr[i].split(",");
		   		$("#receiver").append("<tr id='"+ar[0]+"'><td>"+ar[0]+"<input type='hidden' name='userId' value='"+ar[0]+"'></td><td>"+ar[1]+"<input type='hidden' name='userName' value='"+ar[1]+"'></td><td><a href='#' onclick=deleteRow('"+ar[0]+"')>删除</a></td></tr>");
		   		userIds += ar[0]+",";
		   }
		}
	}
	function deleteRow(userId,messageReceiveId)
	{
		if ( typeof messageReceiveId != 'undefined'  && messageReceiveId!="") {
			if(confirm("确认删除?")){
				var tmp = parseInt(Math.random() * 10000 + 1);
				var url = 'delRecipientMessage.do?a='+tmp+"&messageReceiveId="+messageReceiveId;
				$.get(url, {},function (data, textStatus){
				});
			}
		}
		$("#"+userId).remove();
		var tmp = userIds.split(",");
		var users = "";
		for(var i=0;i<tmp.length;i++)
		{
			if(tmp[i]!=userId&&tmp[i]!="")
			users += tmp[i]+",";
		}
		userIds = users;
		
	}
</script>

		<title>修改草稿箱信息</title>
	</head>
	<body>
		<form action="updateCaogaoMessage.do" name="form1" method="post" enctype="multipart/form-data">
			<div id="body_div">
				<w:ShowTitle name="添加消息信息">
					<w:TitleButton funcName="发送" onClickFunction="saveinfofs()" urlImg="${ctx}/images/main/save1.png" funcType="link" />
					<w:TitleButton funcName="保存草稿" onClickFunction="saveinfobc()" urlImg="${ctx}/images/main/save.png" funcType="link" />
				</w:ShowTitle>
				<div id="body_content">
					<table width="100%">
						<tr>
							<td class="right_align">
								接收人<a href="#" onclick="addUser(this)">(选择)</a><br/>
							</td>
							<td class="left_align">
							
							<table width="200" id="receiver">
								<tr>
									<td class="td_title">用户id</td>
									<td class="td_title">用户姓名</td>
									<td class="td_title">操作</td>
								</tr>
								<c:forEach items="${datalist}" var="obj">
								<tr id="${obj.receiveUserId}">
									<td class="center_align">
									<input type="hidden" name="sysMessageReceive.messageReceiveId" value="${obj.messageReceiveId}"/>
									<input type="hidden" name="sysMessageReceive.receiveUserId" value="${obj.receiveUserId}"/>
									${obj.receiveUserId}</td>
									<td class="center_align"><input type="hidden" name="sysMessageReceive.readUserName" value="${obj.readUserName}"/>${obj.readUserName}</td>
									<td class="center_align"><a href='#' onclick="deleteRow('${obj.receiveUserId}','${obj.messageReceiveId}')">删除</a></td>
								</tr>
								</c:forEach>
							</table>
							</td>
						</tr>
						<tr>
							<td class="right_align">
								消息标题
							</td>
							<td class="left_align">
								<input type="text" name="sysMessage.messageTitle" value="${sysMessage.messageTitle}"/>
								<input type="hidden" name="sysMessage.messageId" value="${sysMessage.messageId}"/>
								<input type="hidden" name="sysMessage.createUserId" value="${sysMessage.createUserId}"/>
								<input type="hidden" name="sysMessage.createUserName" value="${sysMessage.createUserName}"/>
								<input type="hidden" name="sysMessage.createState" id="state"/>
								<input name="sysMessage.messageType" type="hidden" value="${sysMessage.messageType}"/>
							</td>
						</tr>
						<tr>
							<td class="right_align">
								录入日期
							</td>
							<td class="left_align">
								<fmt:formatDate value="${sysMessage.createDate}" pattern="yyyy-MM-dd"/>
							</td>
						</tr>
						<tr>
							<td class="right_align">
								消息内容
							</td>
							<td colspan="3" class="left_align">
								<textarea cols="80" rows="5" name="sysMessage.messageContent">${sysMessage.messageContent}</textarea>
							</td>
						</tr>
						<tr>
							<td class="right_align">
								备注
							</td>
							<td colspan="3" class="left_align">
								<textarea cols="80" rows="3" name="sysMessage.remark">${sysMessage.remark}</textarea>
							</td>
						</tr>
						<tr>
							<td class="right_align">
								附件
							</td>
							<td colspan="3" class="left_align">
								<w:uploadFile isList="true" isAdd="true" beanName="sysMessage" belongId="${sysMessage.messageId}" allowDeletions="true" folder="sysMessage"></w:uploadFile>
							</td>
						</tr>
					</table>
					
				</div>
			</div>
		</form>
	</body>
</html>
